//
// Created by YuWei on 2023/10/24.
//

#pragma once
#include<vector>
#include<memory>
#include "sql/operator/physical_operator.h"
#include "common/rc.h"
#include "sql/parser/value.h"
class FieldMeta;

class Trx;


class UpdatePhysicalOperator : public PhysicalOperator
{
public:
  UpdatePhysicalOperator(Table *table,std::vector<const FieldMeta*> fields,std::vector<Value> values,
   std::vector<std::unique_ptr<PhysicalOperator> > sub_opers) : 
   table_(table),fields_(fields),values_(values),sub_opers_(std::move(sub_opers))
  {}

  virtual ~UpdatePhysicalOperator() = default;

  PhysicalOperatorType type() const override
  {
    return PhysicalOperatorType::UPDATE;
  }
  RC open(Trx *trx) override;
  RC next() override;
  RC close() override;

  Tuple *current_tuple() override
  {
    return nullptr;
  }

private:
  Table *table_ = nullptr;
  std::vector<const FieldMeta*> fields_;
  std::vector<Value> values_;
  std::vector<std::unique_ptr<PhysicalOperator>> sub_opers_;
  Trx* trx_;
};
